<?php

class MSetting extends MSingleton {

    public function  __construct() {
        parent::__construct();
        
        ActiveRecord\Config::initialize(function($cfg){
            $cfg->set_model_directory(__DIR__.DS.'../models');
            $cfg->set_connections(Mandrill::getApp()->dbConnection);
            $cfg->set_default_connection('mandrill');
        });

    }

    public function addSetting($key, $value) {
        Setting::create(array('name'=>$key, 'value'=>$value));
    }


    public function getSetting($key) {
        if($value = self::isSetting($key)) {
            return $value;
        } else {
            return false;
        }
    }

    public function getAllSettings() {
        $settings = Setting::find('all');
        return $settings;
    }

    public function isSetting($key) {
        $setting = Setting::find(array('conditions' => array('name' => $key)));
        if( $setting ) {
            return $setting->value;
        } else {
            return false;
        }
    }

}

?>
